<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2018 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: http://www.dsxcms.com
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2018/8/28
 * Time: 下午11:23
 */

namespace App\WeChat\WxPay\Response;

use App\WeChat\WxPay\Order\WxPayJsApiOrder;

class WxPayUnifiedOrderResponse
{
    private $values = [
        'return_code'=>null,
        'return_msg'=>null,
        'appid'=>null,
        'mch_id'=>null,
        'nonce_str'=>null,
        'sign'=>null,
        'result_code'=>null,
        'prepay_id'=>null,
        'trade_type'=>null,
        'err_code'=>null,
        'err_code_des'=>null,
    ];

    public function __construct($data = [])
    {
        if (!empty($data)) {
            foreach ($data as $key=>$value) {
                $this->values[$key] = $value;
            }
        }
    }

    public function returnCode()
    {
        return $this->values['return_code'];
    }

    public function retrunMsg()
    {
        return $this->values['return_msg'];
    }

    public function appid()
    {
        return $this->values['appid'];
    }

    public function mchId(){
        return $this->values['mch_id'];
    }

    public function nonceStr()
    {
        return $this->values['nonce_str'];
    }

    public function sign()
    {
        return $this->values['sign'];
    }

    public function resultCode()
    {
        return $this->values['result_code'];
    }

    public function prepayId()
    {
        return $this->values['prepay_id'];
    }

    public function tradeType()
    {
        return $this->values['trade_type'];
    }

    public function errCode()
    {
        return $this->values['err_code'];
    }

    public function errCodeDes()
    {
        return $this->values['err_code_des'];
    }

    public function tradeSuccess()
    {
        return $this->resultCode() == 'SUCCESS';
    }

    /**
     * @return array
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function getJsApiContent(){
        $order = new WxPayJsApiOrder();
        $order->setPrepayId($this->prepayId());
        $order->setAppid($this->appid());
        return $order->getBizContent();
    }
}
